package com.swak.fx.support.ui;

import java.net.URL;

import org.controlsfx.glyphfont.FontAwesome;

import com.swak.fx.support.animation.AnimationFX;

import javafx.scene.Node;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.DataFormat;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.util.Duration;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 属性加载
 * 
 * @author 618lf
 */
public class UI {

	/**
	 * UI 常量
	 * 
	 * @author 618lf
	 */
	public static interface Conts {
//		String TempPath_Key = "temp.path";
		String RuntimePath = ".runtime";
		String TempPath = ".temp";
		String StoragePath = "storages"; // 在TempPath 目录下面
		String DownloadPath = "downloads";// 在TempPath 目录下面
		String EventbusThreads_Key = "threads.eventbus";
		String WorkerThreads_Key = "threads.worker";
		String CurrentScreen_Key = "__Current.Screen__"; // 当前的屏幕
		String CurrentScreens_Key = "__Current.Screens__"; // 当前的屏幕

		/**
		 * 数据属性的Key
		 */
		String Pref_Key = "Bind.";
		String ID_Key = "Bind.Id";
		String Index_Key = "Bind.Index";
		String Data_Key = "Bind.Data";
		String Comp_Key = "Bind.Comp";
		String Type_Key = "Bind.Type";
		String Cmd_Key = "Bind.Cmd";

		/**
		 * 全局的配置
		 */
		String Settings_Pref = "settings.";
		String Settings_Page_Width = ".width";
		String Settings_Page_Height = ".height";
		String Settings_Page_X = ".x";
		String Settings_Page_Y = ".y";
		String Settings_Page_Screen = ".screen";
	}

	/**
	 * 主题
	 * 
	 * @author 618lf
	 */
	@Getter
	public static enum Themes {
		Primary, Success, Error, Warning, Danger, Info,
	}

	/**
	 * 状态
	 * 
	 * @author 618lf
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum States {

		Window_Fix(1 << 1), // fix
		Window_Min(1 << 2), // min
		Window_Max(1 << 3), // max
		Window_Show(1 << 4), // Show
		Window_Front(1 << 5);// Front

		public final int index;

		public static boolean isWindowFix(int index) {
			return (index & Window_Fix.index) == Window_Fix.index;
		}

		public static boolean isWindowMin(int index) {
			return (index & Window_Min.index) == Window_Min.index;
		}

		public static boolean isWindowMax(int index) {
			return (index & Window_Max.index) == Window_Max.index;
		}

		public static boolean isWindowShow(int index) {
			return (index & Window_Show.index) == Window_Show.index;
		}

		public static boolean isWindowFront(int index) {
			return (index & Window_Front.index) == Window_Front.index;
		}
	}

	/**
	 * 停靠
	 * 
	 * @author 618lf
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum Berth {
		LEFT, // 左边
		RIGHT, // 右边
		TOP, // 上边
		NONE,// 无
	}

	/**
	 * 定位: 以目标节点为参照物
	 * 
	 * @author 618lf
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum Locations {
		LEFT_BOTTOM, //
		LEFT_CENTER, //
		LEFT_TOP, //
		TOP_LEFT, //
		TOP_CENTER, //
		TOP_RIGHT, //
		RIGHT_BOTTOM, //
		RIGHT_CENTER, //
		RIGHT_TOP, //
		BOTTOM_LEFT, //
		BOTTOM_CENTER, //
		BOTTOM_RIGHT, //
		CENTER,//
	}

	/**
	 * 颜色表
	 * 
	 * @param path
	 * @return
	 */
	public static interface Colors {
		Color White = Color.WHITE;
		Color Font = Color.valueOf("#303133");
		Color FontX = Color.valueOf("#606266");
		Color FontXX = Color.valueOf("#909399");
		Color FontXXX = Color.valueOf("#C0C4CC");

		Color Bg = Color.valueOf("#f5f5f5");
		Color Primary = Color.valueOf("#007aff");
		Color Success = Color.valueOf("#67C23A");
		Color Info = Color.valueOf("#409eff");
		Color Warning = Color.valueOf("#E6A23C");
		Color Danger = Color.valueOf("#DC3545");
	}

	/**
	 * 字体大小
	 * 
	 * @author 618lf
	 */
	public static interface Fonts {
		int Large = 16;
		int Small = 14;
	}

	/**
	 * 常用图标
	 * 
	 * @author 618lf
	 */
	public static interface Icons {
		FontAwesome.Glyph AT = FontAwesome.Glyph.AT;
		FontAwesome.Glyph BEER = FontAwesome.Glyph.BEER;
		FontAwesome.Glyph CLOSE = FontAwesome.Glyph.CLOSE;
		FontAwesome.Glyph PLUS = FontAwesome.Glyph.PLUS;
		FontAwesome.Glyph REMOVE = FontAwesome.Glyph.REMOVE;
		FontAwesome.Glyph SEARCH = FontAwesome.Glyph.SEARCH;
		FontAwesome.Glyph MINUS = FontAwesome.Glyph.MINUS;
		FontAwesome.Glyph SQUARE = FontAwesome.Glyph.SQUARE;
		FontAwesome.Glyph THUMB_TACK = FontAwesome.Glyph.THUMB_TACK;
		FontAwesome.Glyph ELLIPSIS_H = FontAwesome.Glyph.ELLIPSIS_H;
		FontAwesome.Glyph ELLIPSIS_V = FontAwesome.Glyph.ELLIPSIS_V;
		FontAwesome.Glyph COMMENTS = FontAwesome.Glyph.COMMENTS;
		FontAwesome.Glyph SETTINGS = FontAwesome.Glyph.COG;
		FontAwesome.Glyph USER = FontAwesome.Glyph.USER;
		FontAwesome.Glyph USERS = FontAwesome.Glyph.USERS;
		FontAwesome.Glyph LEFT = FontAwesome.Glyph.ANGLE_LEFT;
		FontAwesome.Glyph RIGHT = FontAwesome.Glyph.ANGLE_RIGHT;
		FontAwesome.Glyph EDIT = FontAwesome.Glyph.EDIT;

		FontAwesome.Glyph SUCCESS = FontAwesome.Glyph.CHECK;
		FontAwesome.Glyph ERROR = FontAwesome.Glyph.REMOVE;
		FontAwesome.Glyph WARNGING = FontAwesome.Glyph.EXCLAMATION_TRIANGLE;
	}

	/**
	 * 阴影效果
	 * 
	 * @author 618lf
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum Shadows {

		LEVEL0(Color.rgb(0, 0, 0, 0), 0, 0, 0, 0), //
		LEVEL1(Color.rgb(0, 0, 0, 0.20), 10, 0.12, -1, 2), //
		LEVEL2(Color.rgb(0, 0, 0, 0.20), 15, 0.16, 0, 4), //
		LEVEL3(Color.rgb(0, 0, 0, 0.20), 20, 0.19, 0, 6), //
		LEVEL4(Color.rgb(0, 0, 0, 0.20), 25, 0.25, 0, 8), //
		LEVEL5(Color.rgb(0, 0, 0, 0.20), 30, 0.30, 0, 10);//

		private final Color color;
		private final double radius;
		private final double spread;
		private final double offsetX;
		private final double offsetY;

		public DropShadow shadowOf() {
			return new DropShadow(BlurType.GAUSSIAN, this.getColor(), this.getRadius(), this.getSpread(),
					this.getOffsetX(), this.getOffsetY());
		}

		public Node wrapControl(Node control) {
			Node container = new Pane(control) {
				@Override
				protected double computeMaxWidth(double height) {
					return computePrefWidth(height);
				}

				@Override
				protected double computeMaxHeight(double width) {
					return computePrefHeight(width);
				}

				@Override
				protected double computePrefWidth(double height) {
					return control.prefWidth(height);
				}

				@Override
				protected double computePrefHeight(double width) {
					return control.prefHeight(width);
				}
			};
			container.getStyleClass().add("depth-container");
			container.setPickOnBounds(false);
			container.setEffect(this.shadowOf());
			return container;
		}
	}

	/**
	 * 自定义的事件属性
	 * 
	 * @author 618lf
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum Events {
		Window_Drag("Bind.Window_Drag"), // 拖动、改变大小
		Window_Fix("Bind.Window_Fix"), // 固定
		Window_Min("Bind.Window_Min"), // 最小化
		Window_Max("Bind.Window_Max"), // 单击 最大化
		Window_Max2("Bind.Window_Max2"), // 双击 最大化
		Window_Close("Bind.Window_Close"), // 关闭
		Window_Root_Focused("Bind.Window_Root_Focused");// 让最顶层获得焦点，输入框会失去焦点

		private final String bindKey;
	}

	/**
	 * 滚动的方向
	 * 
	 * @author DELL
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum ScrollDirection {
		UP(-1), RIGHT(-1), DOWN(1), LEFT(1);

		public final int direction;
	}

	/**
	 * 排列的方式
	 * 
	 * Left : 从左开始 Right: 从右开始
	 * 
	 * @author DELL
	 */
	@Getter
	@RequiredArgsConstructor
	public static enum Orientation {
		Left, Right
	}

	/**
	 * 时长设置
	 * 
	 * @author 618lf
	 */
	public static interface Durations {
		Duration FADE_DURATION = Duration.millis(350);
	}

	/**
	 * 效果
	 * 
	 * @author 618lf
	 */
	@Getter
	public static enum Animations {

		/**
		 * Bounce
		 */
		Bounce, BounceIn, BounceInDown, BounceInLeft, BounceInRight, BounceInUp, BounceOut, BounceOutDown,
		BounceOutLeft, BounceOutRight, BounceOutUp,

		/**
		 * Fade
		 */
		FadeIn, FadeInDown, FadeInDownBig, FadeInLeft, FadeInLeftBig, FadeInRight, FadeInRightBig, FadeInUp,
		FadeInUpBig, FadeOut, FadeOutDown, FadeOutDownBig, FadeOutLeft, FadeOutLeftBig, FadeOutRight, FadeOutRightBig,
		FadeOutUp, FadeOutUpBig, Flash, Flip, FlipInX, FlipInY, FlipOutX, FlipOutY,

		/**
		 * Glow
		 */
		GlowBackground, GlowText, Hinge, JackInTheBox, Jello, LightSpeedIn, LightSpeedOut,

		/**
		 * Roll
		 */
		Pulse, RollIn, RollOut, RotateIn, RotateInDownLeft, RotateInDownRight, RotateInUpLeft, RotateInUpRight,
		RotateOut, RotateOutDownLeft, RotateOutDownRight, RotateOutUpLeft, RotateOutUpRight, RubberBand,

		/**
		 * Slide
		 */
		Shake, SlideInDown, SlideInLeft, SlideInRight, SlideInUp, SlideOutDown, SlideOutLeft, SlideOutRight, SlideOutUp,
		Swing, Tada, Wobble,

		/**
		 * Zoom
		 */
		ZoomIn, ZoomInDown, ZoomInLeft, ZoomInRight, ZoomInUp, ZoomOut, ZoomOutDown, ZoomOutLeft, ZoomOutRight,
		ZoomOutUp;

		/**
		 * 实例化： 效果
		 */
		public AnimationFX New() {
			try {
				return (AnimationFX) Class.forName("com.swak.fx.support.animation." + this.name()).getDeclaredConstructor()
						.newInstance();
			} catch (Exception e) {
			}
			return null;
		}

		/**
		 * 实例化： 效果
		 */
		public AnimationFX New(Node node) {
			try {
				return (AnimationFX) Class.forName("com.swak.fx.support.animation." + this.name())
						.getDeclaredConstructor(new Class[] { Node.class }).newInstance(new Object[] { node });
			} catch (Exception e) {
			}
			return null;
		}
	}

	/**
	 * 剪切板数据类型
	 * 
	 * @author 618lf
	 */
	public static interface ClipboardDataFormat {
		DataFormat OBJECT = new DataFormat("java/object");
	}

	public static String load(String path) {
		return loadURL(path).toString();
	}

	public static URL loadURL(String path) {
		return UI.class.getResource(path);
	}
}
